/*
 * @Author: long-xinyu2 2192763423@qq.com
 * @Date: 2025-04-01 10:09:57
 * @LastEditors: long-xinyu2 2192763423@qq.com
 * @LastEditTime: 2025-04-21 11:35:28
 * @FilePath: \algorithm\algorithm-training\lqb\acwing4_1.cpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include<iostream>
#include<cstring>
#include<vector>
#include<map>
#include<cstdio>
#include<algorithm>
#include<string>
#include<string.h>
#include<queue>
#include<math.h>
#include<set>
#include<functional>
#include <bitset>
using namespace std;
using ull = unsigned long long;
using i128 = __int128_t;
//inline int inc(int x,int v,int mod){x+=v;return x>=mod?x-mod:x;}//代替取模+
#define endl '\n'
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
#define int long long

const int N = 1e5+10;

void solve()
{  
    int n;
    cin >> n;
    vector<int>arr(n + 10);
    vector<int>pre(n + 10);
    for(int i = 1; i <= n; i ++) pre[i] = i;
    for(int i = 1; i <= n; i ++) cin >> arr[i];
    sort(arr.begin() + 1,arr.begin() + 1 + n);
    auto find = [&](auto &&self,int x) -> int
    {
        if(pre[x] == x) return x;
        return pre[x] = self(self,pre[x]);
    };
    map<int,int> fir;
    for(int i = 1; i <= n; i ++)
    {
        if(fir[arr[i]] == 0) fir[arr[i]] = i;//某个值的第一个节点
    }
    for(int i = 1; i <= n; i ++)
    {
        if(arr[i] - arr[i - 1] == 1)
        {
            pre[i] = find(find,fir[arr[i - 1]]);
        }
        else
        {
            continue;
        }
    }  

    for(int i = 1; i <= n; i ++)
    {
        if(fir[arr[i]] == i) continue;
        if(find(find,i) != i) continue;
        if(fir[arr[i] + 1] == 0 && fir[arr[i] - 1] == 0) continue;
        if(fir[arr[i] + 1] != 0) pre[i] = find(find,fir[arr[i] + 1]);
        else pre[i] = find(find,fir[arr[i] - 1]);
    }
    map<int,int> mp;
    for(int i = 1; i <= n; i ++)
    {
        mp[pre[i]]++;
    }
    cout << mp.size() - 1 << endl;
}
signed main()
{
    int t = 1;
    cin >> t;
    while(t --)
    {
        solve();
    }
}
